/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.session;

import entity.VendorEntity;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import type.VendorType;

/**
 *
 * @author wei
 */
@Stateless
public class VendorEntityFacade extends AbstractFacade<VendorEntity> {

    @PersistenceContext(unitName = "MacTeam-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public VendorEntityFacade() {
        super(VendorEntity.class);
    }

    public List<VendorEntity> getLockedUser() {
        Query query = (Query) em.createQuery("Select v from Vendor v WHERE v.locked=true");
        List<VendorEntity> list = (List<VendorEntity>) query.getResultList();
        return list;
    }
  public List<VendorEntity> getUnLockedUser() {
        Query query = (Query) em.createQuery("Select v from Vendor v WHERE v.locked=false");
        List<VendorEntity> list = (List<VendorEntity>) query.getResultList();
        return list;
    }

    public List<VendorEntity> getCurrentVendor() {


        String queryStr = "Select v from Vendor v WHERE v.locked=false "
                + " and v.vendorType=:type";
        Query query = em.createQuery(queryStr);
        query.setParameter("type", VendorType.confirmed);
        return query.getResultList();
    }

    public List<VendorEntity> getUnconfirmedVendor() {


        String queryStr = "Select v from Vendor v WHERE v.locked=false "
                + " and v.vendorType=:type";
        Query query = em.createQuery(queryStr);
        query.setParameter("type", VendorType.unconfirmed);
        return query.getResultList();
    }
}
